package com.qzsoft.zhjd.laboratory.modules.tensionProcess.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.laboratory.modules.tensionProcess.entity.TensionProcess;
import com.qzsoft.zhjd.laboratory.modules.tensionProcess.service.TensionProcessService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * (TensionProcess)表控制层
 *
 * @author makejava
 * @since 2023-07-13 10:44:43
 */
@RestController
@AllArgsConstructor
@RequestMapping("/laboratory/tensionProcess")
public class TensionProcessController {

    private TensionProcessService tensionProcessService;

    /**
     * 分页
     *
     * @param params 查询条件
     * @return Result 分页列表
     */
    @GetMapping("page")
    public Result<IPage<TensionProcess>> page(@RequestParam Map<String, Object> params) {
        IPage<TensionProcess> page = tensionProcessService.page(params);
        return ResultUtils.ok(page);
    }

    @GetMapping("/find/{id}")
    public Result getInfo(@PathVariable("id") String id) {
        return ResultUtils.ok(tensionProcessService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param tensionProcess 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody TensionProcess tensionProcess) {
//        if(tensionProcess.getCode()!=null){
//            QueryWrapper<TensionProcess> queryWrapper = new QueryWrapper<TensionProcess>();
//            queryWrapper.eq("code",tensionProcess.getCode());
//            queryWrapper.eq("link_code",tensionProcess.getLinkCode());
//            List<TensionProcess> result = tensionProcessService.list(queryWrapper);
//            if(result.size()==0){
//                tensionProcessService.insertTensionProcess(tensionProcess);
//            }
//        }else{
//            tensionProcessService.insertTensionProcess(tensionProcess);
//        }
        tensionProcessService.insertTensionProcess(tensionProcess);
        return ResultUtils.ok();
    }

    /**
     * 修改数据
     *
     * @param tensionProcess 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateTensionProcess")
    public Result update(@RequestBody TensionProcess tensionProcess) {
        tensionProcessService.updateTensionProcess(tensionProcess);
        return ResultUtils.ok();
    }

    /**
     * 删除数据
     *
     * @param ids 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/deleteByIds")
    public Result delete(@RequestBody String[] ids) {
        tensionProcessService.deleteByIds(Arrays.asList(ids));
        return ResultUtils.ok();
    }
}

